#include "draw_utils.h"

void drawLine( const D3DXVECTOR3 &src
			 , const D3DXVECTOR3 &dst
			 , unsigned color ) {
	CUSTOMVERTEX v[2];
	v[0].loc = src;
	v[0].color = color;
	v[1].loc = dst;
	v[1].color = color;
    g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
	g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINELIST
		                         , 1
								 , v
								 , sizeof(CUSTOMVERTEX)
								 );
}

void drawAxis( ) {
	drawLine( D3DXVECTOR3( 0,0,0 ), D3DXVECTOR3( 1,0,0 ), D3DCOLOR_XRGB( 255, 0, 0 ) );
	drawLine( D3DXVECTOR3( 0,0,0 ), D3DXVECTOR3( 0,2,0 ), D3DCOLOR_XRGB( 0, 255, 0 ) );
	drawLine( D3DXVECTOR3( 0,0,0 ), D3DXVECTOR3( 0,0,3 ), D3DCOLOR_XRGB( 0, 0, 255 ) );
}

void drawGridXZ( int nblocks, int nsubsamples ) {
	int nsamples = nblocks * nsubsamples;
	unsigned color1 = D3DCOLOR_XRGB( 80, 80, 80 );
	unsigned color2 = D3DCOLOR_XRGB( 160, 160, 160 );
	for( int i=-nsamples; i<=nsamples; ++i ) {
		unsigned color = ( i % nsubsamples ) == 0 ? color2 : color1;
		drawLine( D3DXVECTOR3( i,0,nsamples )
			    , D3DXVECTOR3( i,0,-nsamples )
				, color );
		drawLine( D3DXVECTOR3( nsamples,0,i )
			    , D3DXVECTOR3( -nsamples,0,i )
				, color );
	}
}
